using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// Summary description for processProductType
/// </summary>
public class processProductType:DBConnectionTool
{
	public processProductType() : base()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public string getProductTypeID()
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("select right(max(ProductTypeID),2) from ProductTypes", cn);
        String s = cmd.ExecuteScalar().ToString();
        Int32 result;
        if (Int32.TryParse(s, out result))
            result++;
        else
            result = 1;
        int l = result.ToString().Length;
        int count = 2 - l;
        string sresult = "PrT";
        for (int i = 0; i < count; i++)
        {
            sresult = sresult + "0";
        }
        sresult = sresult + result;
        CloseCn();
        return sresult;
    }
    public DataTable getProductTypes()
    {
        DataTable dt = new DataTable("ProductTypes");
        OpenCn();
        SqlDataAdapter da = new SqlDataAdapter("select * from ProductTypes", cn);
        da.Fill(dt);
        CloseCn();
        return dt;
    }
    public DataTable getProductTypeByID(string ProductTypeID)
    {
        OpenCn();
        SqlDataAdapter da = new SqlDataAdapter("select * from ProductTypes where ProductTypes.ProductTypeID='" + ProductTypeID + "'", cn);
        DataTable dt = new DataTable("ProductTypes");
        da.Fill(dt);
        CloseCn();
        return dt;
    }

    public int insertProductType(string ProductTypeID, string ProductTypeName)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Insert Into ProductTypes(ProductTypeID,ProductTypeName) Values(@ProductTypeID,@ProductTypeName)", cn);
        cmd.Parameters.Add(new SqlParameter("@ProductTypeID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@ProductTypeName", SqlDbType.NVarChar, 200));        
        cmd.Parameters["@ProductTypeID"].Value = ProductTypeID;
        cmd.Parameters["@ProductTypeName"].Value = ProductTypeName;        
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
    public int updateProductType(string ProductTypeID, string ProductTypeName)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("update ProductTypes set ProductTypeName=@ProductTypeName where ProductTypeID=@ProductTypeID", cn);
        cmd.Parameters.Add(new SqlParameter("@ProductTypeID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@ProductTypeName", SqlDbType.NVarChar, 200));
        cmd.Parameters["@ProductTypeID"].Value = ProductTypeID;
        cmd.Parameters["@ProductTypeName"].Value = ProductTypeName;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    public int deleteProductType(string ProductTypeID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Delete ProductTypes Where ProductTypeID ='" + ProductTypeID + "'", cn);
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

}
